/**
 * @Title: UserController.java
 * @Package com.lemon.controller.cityRun
 * @Description: (一句话阐述):
 * @author Ran_cc
 * @date 2018年10月17日
 * @version V1.0
 */
package com.lemon.controller.cityRun;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.lemon.conf.MyException;
import com.lemon.conf.MyInterceptor.LoginRequired;
import com.lemon.conf.content.IdTypeHandler;
import com.lemon.conf.redis.RedisUtil;
import com.lemon.controller.BaseController;
import com.lemon.model.buy.PayTransfersResult;
import com.lemon.model.cityRun.CrShopSet;
import com.lemon.model.cityRun.CrShopUser;
import com.lemon.model.cityRun.CrShops;
import com.lemon.model.cityRun.CrUserTransactionRecord;
import com.lemon.service.cityRun.CrShopUserService;
import com.lemon.service.cityRun.CrShopsService;
import com.lemon.service.cityRun.CrSysRuleService;
import com.lemon.service.cityRun.CrUserTransactionRecordService;
import com.lemon.utils.HttpUtil;
import com.lemon.utils.ReqResult;
import com.lemon.utils.StringUtil;
import com.lemon.utils.pay.PayUtil;
import com.lemon.utils.sval.StaticValues;
import com.lemon.utils.wx.WeiXinUtils;

/**
 * <p>
 * Title: CrShopsController
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Ran_cc
 * @date 2018年11月10日
 * @版本 V 1.0
 */
@RestController
@RequestMapping("/shop")
public class CrShopsController extends BaseController {

	@Resource
	private CrShopsService shopService;
	@Resource
	private CrShopUserService userService;
	@Resource
	private CrSysRuleService ruleService;

	@Resource
	private CrUserTransactionRecordService trService;

	//获取全部用户信息
	@LoginRequired
	@RequestMapping("/getShopsList")
	public ReqResult getShopsList(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser u = (CrShopUser) request.getSession().getAttribute("user");
			long ri = IdTypeHandler.decode(u.getRuleId());

			String start = request.getParameter("startTime");
			String end = request.getParameter("endTime");
			StringBuffer buffer = new StringBuffer();

			buffer.append(
					"  and a.shop_status != 0  and a.shop_status != 4 and a.shop_status != 5  and a.shop_status != 6 ");
			if (StringUtil.isNotBlank(start) && StringUtil.isNotBlank(end)) {
				buffer.append(" and ( a.server_end_time >= '");
				buffer.append(start);
				buffer.append("' and  a.server_end_time <= '");
				buffer.append(end);
				buffer.append("') ");
			} else if (StringUtil.isNotBlank(start)) {
				buffer.append(" and a.server_end_time >= '");
				buffer.append(start + "'");
			} else if (StringUtil.isNotBlank(end)) {
				buffer.append(" and a.server_end_time <= '");
				buffer.append(end + "'");
			}
			if (u.getUserType() == 1) {
				shop.setWhere(buffer.toString());
				//查询管理员列表
				shop.setOrderBy(" order by a.create_time desc ");
				List<CrShops> list = shopService.selectListBySelective(shop);
				reqResult.setReturnResult(list);
			}
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	//获取全部用户信息
	@LoginRequired
	@RequestMapping("/getShopAuditList")
	public ReqResult getShopAuditList(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser u = (CrShopUser) request.getSession().getAttribute("user");
			long ri = IdTypeHandler.decode(u.getRuleId());
			StringBuffer buffer = new StringBuffer();
			buffer.append(
					"  and a.shop_status != 0  and a.shop_status != 1 and a.shop_status != 2  and a.shop_status != 3 ");
			if (u.getUserType() == 1) {
				shop.setWhere(buffer.toString());
				shop.setOrderBy(" order by a.create_time desc ");
				List<CrShops> list = shopService.selectAuditListBySelective(shop);
				reqResult.setReturnResult(list);
			}
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	//获取全部用户信息
	@LoginRequired
	@RequestMapping("/getShopById")
	public ReqResult getShopById(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser u = (CrShopUser) request.getSession().getAttribute("user");
			//			long ri = IdTypeHandler.decode(u.getRuleId());
			//			if (ri == 0 || ri == 2) {
			//				reqResult.setReturnResult("权限不足" , ReqResult.code_no_permission);
			//				return reqResult;
			//			}
			//			if (u.getUserType() == 1) {
			CrShops list = shopService.selectShopAndUserBySel(shop);
			//				if (list.getShopInCharge() != null && list.getShopInCharge() != 0) {
			//					list.setShopInCharge(list.getShopInCharge() / 100);
			//				}
			//				CrShops list = shopService.selectShopById(shop.getId());
			reqResult.setReturnResult(list);
			//			}
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	//获取全部用户信息
	@RequestMapping("/getShopByIdperv")
	public ModelAndView getShopByIdperv(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		try {
			shop.setOrderBy(" order by a.create_time desc ");
			CrShops list = shopService.selectShopAndUserBySel(shop);
			if (StringUtil.isEmpty(list.getShopQrcode())) {
				String wxacode = WeiXinUtils.getWxacode("pages/shopInfo/shopInfo" , list.getId());
				list.setShopQrcode(wxacode);
				shopService.updateShopInfo(list);
			}
			ModelAndView m = new ModelAndView();
			m.addObject("shop" , list);
			m.setViewName("../public/back/admin/shops/shop-info-i.html");
			return m;
		} catch (Exception e) {
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return null;
	}

	/**
	 * <b>Description:<blockquote> 审核详情页面
	 * </blockquote></b>
	 * 
	 * @Title: getShopByIdpervii
	 * @param shop
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月10日
	 */
	@RequestMapping("/getShopByIdpervii")
	public ModelAndView getShopByIdpervii(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		try {
			CrShops list = shopService.selectShopAndUserBySel(shop);
			ModelAndView m = new ModelAndView();
			m.addObject("shop" , list);
			m.setViewName("../public/back/admin/shop-audit-info.html");
			return m;
		} catch (Exception e) {
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return null;
	}

	@RequestMapping("/updateShopByIdperv")
	public ReqResult updateShopByIdperv(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser user = new CrShopUser();
			CrShops shops = shopService.selectShopById(shop.getId());
			user.setId(shops.getShopUserId());
			user.setUserContact(shop.getUserContact());
			if (null != shop.getShopStatus() && (shop.getShopStatus() == 3 || shop.getShopStatus() == 5)) {
				user.setUserStatus(1);
			} else if (null != shop.getShopStatus() && shop.getShopStatus() == 6) {
				//被拒绝后 , 开始发生退款操作
				//先查出来用户支付的单号
				CrUserTransactionRecord tran = new CrUserTransactionRecord();
				tran.setShopUserId(shops.getShopUserId());
				tran.setTranType(3);
				CrUserTransactionRecord tr = trService.selectBySelective(tran);
				//根绝单号去微信商户退款操作
				//开始退款
				if (tr != null) {
					PayTransfersResult payResult = PayUtil.transfers(tr.getShopUserWx() , "退款" , tr.getAmount() ,
							tr.getSerialNumber() , HttpUtil.getUsrIPAddr(request));
					int status = 0;
					if (payResult.isSuccess()) {//成功
						status = 2;
					} else {//去查询 //如果未成功 则抛出异常 成功 未知 需要 继续查询
						if (payResult.getErrCode().equals("NOTENOUGH")) {
							reqResult.setReturnResult("商户账户余额不足" , ReqResult.code_objecr_number);
							return reqResult;
						}
						status = 0;
						if (payResult.getErrCode().equals("SEND_FAILED")
								|| payResult.getErrCode().equals("SYSTEMERROR")) {
							status = 1;
							payResult = PayUtil.getTransferinfo(tr.getSerialNumber());
							if (payResult.isSuccess()) {
								status = 2;

							} else {
								if ("FAILED".equals(payResult.getStatus())) {
									status = 0;
								}
							}
						}
					}
				}
				//int row = trService.updateShopTranInfo(tran);
				//reqResult.setReturnResult(1);
				user.setUserStatus(0);
			} else if (null != shop.getShopStatus() && shop.getShopStatus() == 4) {
				String wxacode = WeiXinUtils.getWxacode("pages/shopInfo/shopInfo" , shop.getId());
				shop.setShopQrcode(wxacode);
			}
			shopService.updateShopAndUserInfo(shop , user);
			//如果修改了支付方式 则修改对应的 缓存
			if (StringUtil.isNotBlank(shop.getPayTypeOut())) {
				CrShopSet shop2 = new CrShopSet();
				shop2.setShopId(shop.getId());
				CrShopSet set = shopService.selectShopSetByShopId(shop2);
				RedisUtil.set("cityRun:set:set_" + shop.getId() , set);
			}

		} catch (Exception e) {
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	//获取全部用户信息
	@RequestMapping("/selectSURbYuid")
	public ReqResult selectSURbYuid(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShops s = shopService.selectShopAndUserBySel(shop);
			reqResult.setReturnResult(s);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote> 新增管理员信息
	 * </blockquote></b>
	 * 
	 * @Title: addAdminUserInfo
	 * @param user
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月18日
	 */
	@LoginRequired
	@RequestMapping(value = "/addShopInfo.do" , method = RequestMethod.POST)
	public ReqResult addShopInfo(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			CrShops s = new CrShops();
			s.setAddressArea(shop.getAddressArea());
			s.setAddressProvince(shop.getAddressProvince());
			s.setAddressCity(shop.getAddressCity());
			s.setAddressInfo(shop.getAddressInfo());
			s.setLongitude(shop.getAddressLocation().split(",")[0]);
			s.setLatitude(shop.getAddressLocation().split(",")[1]);
			s.setServerEndTime(StringUtil.StringToDate(request.getParameter("serverEndTimeD") , 0));
			s.setShopLicense(shop.getShopLicense());
			s.setShopLogo(shop.getShopLogo());
			s.setShopStatus(4);
			s.setShopType(shop.getShopType());
			s.setShopTitle(shop.getShopTitle());
			s.setShopInCharge(shop.getShopInCharge() * 100);

			CrShopUser u = new CrShopUser();
			u.setRuleId(IdTypeHandler.encode(StaticValues.RULE_ID_SHOP_USER));
			u.setUserAccount(shop.getUserAccount());
			u.setUserPwd(shop.getUserPwd().toUpperCase());
			u.setUserCardBack(shop.getUserCardBack());
			u.setUserCardFront(shop.getUserCardFront());
			u.setUserContact(shop.getUserContact());
			u.setUserType(2);
			u.setUserWx(shop.getUserWx());
			u.setUserWxName(shop.getUserWxName());
			u.setUserStatus(0);
			u.setUserName(shop.getUserName());
			u.setUserIdCard(shop.getUserIdCard());

			//			CrShopUser uu = (CrShopUser) request.getSession().getAttribute("user");
			//			long ri = IdTypeHandler.decode(u.getRuleId());
			//		  if (ri == 0 || ri == 2) {
			//		  reqResult.setReturnResult("权限不足" , ReqResult.code_no_permission);
			//		  return reqResult;
			//		  }
			CrShopUser acc = userService.selectShopUserByAcc(u.getUserAccount());
			if (acc != null) {
				reqResult.setReturnResult("当前账号已存在" , ReqResult.code_exist);
				return reqResult;
			}
			//开始添加数据

			shopService.insertShopsAndSUserInfo(u , s);

			reqResult.setReturnResult("");

		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote> 新增管理员信息
	 * </blockquote></b>
	 * 
	 * @Title: addAdminUserInfo
	 * @param user
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月18日
	 */
	@LoginRequired
	@RequestMapping(value = "/updateShopInfo.do" , method = RequestMethod.POST)
	public ReqResult updateShopInfo(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser u = new CrShopUser();
			CrShops s = new CrShops();
			String ids = request.getParameter("remAllIds");
			CrShopUser uu = (CrShopUser) request.getSession().getAttribute("user");
			long ri = IdTypeHandler.decode(uu.getRuleId());
			s.setShopStatus(shop.getShopStatus());
			//暂不支持修改账号  //后面可以添加修改账号的功能
			if (null != shop.getShopStatus()) {
				if (shop.getShopStatus() == 0 || shop.getShopStatus() == 6) {
					int row = shopService.updateShopInfo(shop);
					reqResult.setReturnObject(row);
					return reqResult;
				} else if (shop.getShopStatus() == 5) {
					u.setUserStatus(1);
					s.setShopStatus(3);
				}
			}
			s.setAddressArea(shop.getAddressArea());
			s.setAddressProvince(shop.getAddressProvince());
			s.setAddressCity(shop.getAddressCity());
			s.setAddressInfo(shop.getAddressInfo());
			if (StringUtil.isNotBlank(shop.getAddressLocation())) {
				s.setLongitude(shop.getAddressLocation().split(",")[0]);
				s.setLatitude(shop.getAddressLocation().split(",")[1]);
			}
			s.setServerEndTime(StringUtil.StringToDate(request.getParameter("serverEndTimeD") , 0));
			s.setShopLicense(shop.getShopLicense());
			s.setShopLogo(shop.getShopLogo());
			s.setShopType(shop.getShopType());
			s.setShopTitle(shop.getShopTitle());
			s.setShopInCharge(shop.getShopInCharge() * 100);
			s.setId(shop.getId());
			s.setMark(shop.getMark());

			u.setUserAccount(shop.getUserAccount());
			u.setUserPwd(shop.getUserPwd().toUpperCase());
			u.setUserCardBack(shop.getUserCardBack());
			u.setUserCardFront(shop.getUserCardFront());
			u.setUserContact(shop.getUserContact());
			u.setUserWx(shop.getUserWx());
			u.setUserWxName(shop.getUserWxName());
			u.setUserName(shop.getUserName());
			u.setUserIdCard(shop.getUserIdCard());
			u.setId(shop.getShopUserId());
			//如果修改了支付方式 则修改对应的 缓存
			int row = shopService.updateShopAndUserInfo(s , u);
			if (StringUtil.isNotBlank(shop.getPayTypeOut())) {
				CrShopSet shop2 = new CrShopSet();
				shop2.setShopId(shop.getId());
				CrShopSet set = shopService.selectShopSetByShopId(shop2);
				RedisUtil.set("cityRun:set:set_" + shop.getId() , set);
			}
			reqResult.setReturnResult(row);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote>仅修改商店信息
	 * </blockquote></b>
	 * 
	 * @Title: addAdminUserInfo
	 * @param user
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年10月18日
	 */
	@LoginRequired
	@RequestMapping(value = "/updateShopInfoOnly.do" , method = RequestMethod.POST)
	public ReqResult updateShopInfoOnly(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			//如果修改了支付方式 则修改对应的 缓存
			int row = shopService.updateShopInfo(shop);
			if (StringUtil.isNotBlank(shop.getPayTypeOut())) {
				CrShopSet shop2 = new CrShopSet();
				shop2.setShopId(shop.getId());
				CrShopSet set = shopService.selectShopSetByShopId(shop2);
				RedisUtil.set("cityRun:set:set_" + shop.getId() , set);
			}
			reqResult.setReturnResult(row);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	@LoginRequired
	@RequestMapping(value = "/updateShopInfoBySel.do" , method = RequestMethod.POST)
	public ReqResult updateShopInfoBySel(@ModelAttribute CrShops shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			CrShopUser u = new CrShopUser();
			String ids = request.getParameter("remAllIds");
			CrShopUser uu = (CrShopUser) request.getSession().getAttribute("user");
			long ri = IdTypeHandler.decode(uu.getRuleId());
			//暂不支持修改账号  //后面可以添加修改账号的功能
			int row = shopService.updateShopInfo(shop);
			//如果修改了支付方式 则修改对应的 缓存
			if (StringUtil.isNotBlank(shop.getPayTypeOut())) {
				CrShopSet shop2 = new CrShopSet();
				shop2.setShopId(shop.getId());
				CrShopSet set = shopService.selectShopSetByShopId(shop2);
				RedisUtil.set("cityRun:set:set_" + shop.getId() , set);
			}
			reqResult.setReturnResult(row);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	////////////////////////关于门店的设置信息//////////////////////////////////////
	/**
	 * <b>Description:<blockquote> 查询门店的设置信息
	 * </blockquote></b>
	 * 
	 * @Title: getShopSetBySID
	 * @param shop
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月1日
	 */
	@LoginRequired
	@RequestMapping("/getShopSetBySID")
	public ReqResult getShopSetBySID(@ModelAttribute CrShopSet shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			String string = RedisUtil.get("cityRun:set:set_" + shop.getShopId());
			if (StringUtil.isNotBlank(string) && !"null".equals(string)) {
				reqResult.setReturnResult(JSONObject.parse(string));
				return reqResult;
			}
			CrShopSet set = shopService.selectShopSetByShopId(shop);
			if (null == set && StringUtil.isNotBlank(shop.getShopId())) {
				//添加一条信息的设置信息
				shopService.insertShopSetInfo(shop);
				set = shopService.selectShopSetByShopId(shop);
				RedisUtil.set("cityRun:set:set_" + shop.getShopId() , set);
			}
			reqResult.setReturnResult(set);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote> 修改门店的设置信息
	 * </blockquote></b>
	 * 
	 * @Title: getShopSetBySID
	 * @param shop
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月1日
	 */
	@LoginRequired
	@RequestMapping("/updateShopSetBySID")
	public ReqResult updateShopSetBySID(@ModelAttribute CrShopSet shop , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			int row = shopService.updateShopSetByShopId(shop);
			CrShopSet shop2 = new CrShopSet();
			shop2.setShopId(shop.getShopId());
			CrShopSet set = shopService.selectShopSetByShopId(shop2);
			RedisUtil.set("cityRun:set:set_" + shop.getShopId() , set);
			reqResult.setReturnResult(row);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/////////////////////////打印机相关////////////////////

	/**
	 * <b>Description:<blockquote> 数据统计查询
	 * </blockquote></b>
	 * 
	 * @Title: getDataStatisInfo
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月5日
	 */
	@RequestMapping("/getDataStatisInfo.do")
	public ReqResult getDataStatisInfo(@ModelAttribute CrShops crShops , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {
			log.info("查询上面统计的数字内容");
			String start = request.getParameter("startTime");
			String end = request.getParameter("endTime");
			if (StringUtil.isNotBlank(end) && StringUtil.isNotBlank(start)) {
				crShops.setWhere(" and a.create_time >= ? and  a.create_time < ? " , start , end);
			} else if (StringUtil.isNotBlank(start)) {
				crShops.setWhere(" and a.create_time >= ? " , start);
			} else if (StringUtil.isNotBlank(end)) {
				crShops.setWhere(" and a.create_time < ? " , end);
			}

			if (StringUtil.isEmpty(crShops.getAddressCity())) {
				crShops.setAddressCity(null);
			}
			if (StringUtil.isEmpty(crShops.getAddressProvince())) {
				crShops.setAddressProvince(null);
			}
			if (StringUtil.isEmpty(crShops.getAddressArea())) {
				crShops.setAddressArea(null);
			}
			//			crShops.setWhereAppend(
			//					" and (a.shop_status =1 or  a.shop_status =2 or a.shop_status = 3  or a.shop_status = 31 or a.shop_status = 32 or a.shop_status = 4 )");
			Map<String , Object> map = shopService.getDataStatisInfo(crShops);
			reqResult.setReturnResult(map);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

	/**
	 * <b>Description:<blockquote>查询每个商店的订单数以及盈利信息
	 * </blockquote></b>
	 * 
	 * @Title: getShopOrderProfitInfo
	 * @param crShops
	 * @param request
	 * @param response
	 * @return
	 * @author Ran_cc
	 * @date 2018年11月5日
	 */
	@RequestMapping("/getShopOrderProfitInfo")
	public ReqResult getShopOrderProfitInfo(@ModelAttribute CrShops crShops , HttpServletRequest request ,
			HttpServletResponse response) {
		ReqResult reqResult = new ReqResult();
		try {

			String start = request.getParameter("startTime");
			String end = request.getParameter("endTime");
			if (StringUtil.isNotBlank(end) && StringUtil.isNotBlank(start)) {
				crShops.setWhere(" and a.create_time >= ? and  a.create_time < ? " , start , end);
			} else if (StringUtil.isNotBlank(start)) {
				crShops.setWhere(" and a.create_time >= ? " , start);
			} else if (StringUtil.isNotBlank(end)) {
				crShops.setWhere(" and a.create_time < ? " , end);
			}

			if (StringUtil.isEmpty(crShops.getAddressCity())) {
				crShops.setAddressCity(null);
			}
			if (StringUtil.isEmpty(crShops.getAddressProvince())) {
				crShops.setAddressProvince(null);
			}

			//			crShops.setWhereAppend(" and (a.shop_status =1 or  a.shop_status =2 or a.shop_status = 3)");
			//			crShops.setWhereAppend(
			//					" and (a.shop_status =1 or  a.shop_status =2 or a.shop_status = 3  or a.shop_status = 31 or a.shop_status = 32 or a.shop_status = 4 )");

			List<CrShops> shops = shopService.getShopOrderProfitInfo(crShops);
			reqResult.setReturnResult(shops);
		} catch (Exception e) {
			reqResult.setReturnResult("" , ReqResult.code_error);
			MyException.writeErr(e , "查询客户或管理员列表失败");
		}
		return reqResult;
	}

}
